package com.aixingfu.sports.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.aixingfu.sports.MVP.contract.SearchContract;
import com.aixingfu.sports.MVP.presenter.SearchPresenter;
import com.aixingfu.sports.Model.SearchModel;
import com.aixingfu.sports.R;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.orie.librarybase.base.BaseActivity;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//搜索
@Route(path = "/main/SearchActivity")
public class SearchActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.ed_search)
    EditText edSearch;
    @BindView(R.id.tv_search)
    TextView tvSearch;
    private SearchPresenter searchPresenter;
    @Override
    protected int provideContentViewId() {
        return R.layout.activity_search;
    }

    public static void startActivityByRoute() {
        ARouter.getInstance().build("/main/SearchActivity").navigation();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        tvTitle.setText("搜索会员");
    }
    @Override
    protected void initEvent() {
    }
    @Override
    protected void beforeInit() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.iv_back, R.id.tv_search})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                hideIputKeyboard();
                finish();
                break;
            case R.id.tv_search:
                hideIputKeyboard();
                String search = edSearch.getText().toString();
                if (TextUtils.isEmpty(search)){

                }else {
//                getSearch(search);
                    ARouter.getInstance().build("/main/MemberListActivity").withString("keywords",search).navigation();
                }

                break;
        }
    }
    //关闭软键盘
    public void hideIputKeyboard() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                InputMethodManager mInputKeyBoard = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                if (getCurrentFocus() != null) {
                    mInputKeyBoard.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                }
            }
        });
    }
}
